/* ----------------------------------------------------------------------------
* File: mutex.h
*
* Desc: CMutexLocker class to control mutex
*
* Created: 05/03/2011, by Alexey Korshunov
* ---------------------------------------------------------------------------- */
#ifndef _MUTEX_H_
#define _MUTEX_H_

#include <pthread.h>


/************************************************************************/
/*	CMutexLocker class to lock access									*/
/************************************************************************/
class CMutexLocker
{
	// lock copy constructor and assignment operation
	CMutexLocker(const CMutexLocker&);
	CMutexLocker& operator=(const CMutexLocker&);
public:
	explicit CMutexLocker(pthread_mutex_t& mutex):
	m_mutex(&mutex)
	{
		pthread_mutex_lock(m_mutex);
	}

	~CMutexLocker()
	{
		pthread_mutex_unlock(m_mutex);
	}
private:
	pthread_mutex_t *m_mutex;
};

#endif // _MUTEX_H_